package com.lin.cms.domain;

import static com.lin.cms.base.Constants.TPLDIR_ALONE;
import static com.lin.cms.base.Constants.TPLDIR_CHANNEL;
import static com.lin.cms.base.Constants.TPL_SUFFIX;
import static com.lin.cms.common.web.Constants.DEFAULT;
import static com.lin.cms.base.Constants.TPLDIR_CONTENT;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;

public class Model implements Serializable {

	private static final long serialVersionUID = 1L;

	private int modelId;

	private String modelName;

	private String modelPath;

	private String tplChannelPrefix;

	private String tplContentPrefix;

	private int titleImgWidth;

	private int titleImgHeight;

	private int contentImgWidth;

	private int contentImgHeight;

	private int priority;

	private Boolean hasContent;

	private String isDisabled;

	private String isDef;

	public Model() {
	}

	public int getModelId() {
		return modelId;
	}

	public void setModelId(int modelId) {
		this.modelId = modelId;
	}

	public String getModelName() {
		return modelName;
	}

	public void setModelName(String modelName) {
		this.modelName = modelName;
	}

	public String getModelPath() {
		return modelPath;
	}

	public void setModelPath(String modelPath) {
		this.modelPath = modelPath;
	}

	public String getTplChannelPrefix() {
		return tplChannelPrefix;
	}

	public void setTplChannelPrefix(String tplChannelPrefix) {
		this.tplChannelPrefix = tplChannelPrefix;
	}

	public String getTplContentPrefix() {
		return tplContentPrefix;
	}

	public void setTplContentPrefix(String tplContentPrefix) {
		this.tplContentPrefix = tplContentPrefix;
	}

	public int getTitleImgWidth() {
		return titleImgWidth;
	}

	public void setTitleImgWidth(int titleImgWidth) {
		this.titleImgWidth = titleImgWidth;
	}

	public int getTitleImgHeight() {
		return titleImgHeight;
	}

	public void setTitleImgHeight(int titleImgHeight) {
		this.titleImgHeight = titleImgHeight;
	}

	public int getContentImgWidth() {
		return contentImgWidth;
	}

	public void setContentImgWidth(int contentImgWidth) {
		this.contentImgWidth = contentImgWidth;
	}

	public int getContentImgHeight() {
		return contentImgHeight;
	}

	public void setContentImgHeight(int contentImgHeight) {
		this.contentImgHeight = contentImgHeight;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}
	

	public Boolean getHasContent() {
		return hasContent;
	}

	public void setHasContent(Boolean hasContent) {
		this.hasContent = hasContent;
	}

	public String getIsDisabled() {
		return isDisabled;
	}

	public void setIsDisabled(String isDisabled) {
		this.isDisabled = isDisabled;
	}

	public String getIsDef() {
		return isDef;
	}

	public void setIsDef(String isDef) {
		this.isDef = isDef;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + modelId;

		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final Model other = (Model) obj;
		if (modelId != other.modelId)
			return false;

		return true;
	}
	
	@Override
	public String toString() {
		return getClass().getName() + "@" + Integer.toHexString(hashCode()) + 
			"(" + 
			"modelId=" + "'" + modelId + "'" + 
			")";
	}
	
	public String getTplContent(String solution, boolean def) {
		StringBuilder t = new StringBuilder();
		t.append(solution).append("/");
		t.append(TPLDIR_CONTENT);
		t.append("/");
		String prefix = getTplContentPrefix();
		if (def) {
			if (!StringUtils.isBlank(prefix)) {
				t.append(prefix);
			} else {
				t.append(DEFAULT);
			}
			t.append(TPL_SUFFIX);
		} else {
			if (!StringUtils.isBlank(prefix)) {
				t.append(prefix);
			}
		}
		return t.toString();

	}
	
	public String getTplChannel(String solution, boolean def) {
		StringBuilder t = new StringBuilder();
		t.append(solution).append("/");
		if (getHasContent()) {
			t.append(TPLDIR_CHANNEL);
		} else {
			t.append(TPLDIR_ALONE);
		}
		t.append("/");
		String prefix = getTplChannelPrefix();
		if (def) {
			if (!StringUtils.isBlank(prefix)) {
				t.append(prefix);
			} else {
				t.append(DEFAULT);
			}
			t.append(TPL_SUFFIX);
		} else {
			if (!StringUtils.isBlank(prefix)) {
				t.append(prefix);
			}
		}
		return t.toString();
	}
	
	
}
